<style>
    .image {
        width: 60px;
        height: 60px;
    }
</style>
<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">

        <div class="layui-form-item" id="product">
            <label class="layui-form-label">spu商品</label>
            <div id="images">
                <img src="__STATIC__/admin/images/+.jpg" data-url="selectGoods" data-method="offset"
                     style="border: 1px dashed black;" class="image">
            </div>
            <input type="hidden" id="goods_id" name="goods_id">
        </div>
        <div class="layui-form-item" id="goodsSku">
            <label class="layui-form-label">sku商品</label>
            <div id="sku_images">
                <img src="__STATIC__/admin/images/+.jpg" data-url="selectGoodsSku" data-method="offset"
                     style="border: 1px dashed black;" class="image">
            </div>
            <input type="hidden" id="sku_id" name="sku_id">
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">需要积分</label>
            <div class="layui-input-block">
                <input type="text" name="need_integral" class="layui-input" lay-verify="required" placeholder="请输入需要积分" value="0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">库存</label>
            <div class="layui-input-block">
                <input type="text" name="stock" class="layui-input" lay-verify="required" placeholder="请输入库存" value="0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否上架</label>
            <div class="layui-input-block">
                {foreach $getIsStatusList as $k=>$v}
                <input type="radio" name="is_status" value="{$k}" title="{$v}" {in name="k" value="1"}checked=""{/in}>
                {/foreach}
            </div>
        </div>

        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>确认</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>
<script>
    layui.use(['jquery', 'form', 'upload', 'element', 'layer'], function () {
        var $ = layui.jquery;
        layer = layui.layer;

        var active = {
            offset: function (othis, url) {
                var type = othis.data('type')
                let goods_id = $("#goods_id").val();
                if (url == undefined) {
                    return false;
                }
                //添加商品
                layer.open({
                    type: 2
                    , area: ['800px', '600px']
                    , offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    , id: 'layerDemo' + type //防止重复弹出
                    , content: "{:url('store.goods/" + url + "')}?goods_id=" + goods_id
                    , btnAlign: 'c' //按钮居中
                    , shade: 0 //不显示遮罩
                    , yes: function () {
                        layer.closeAll();
                    }
                    , end: function (e) {
                        let sku_id = $("#sku_id").val();
                        console.log(sku_id);
                        if (sku_id !== '') {
                            $.ajax({
                                url: "{:url('store.goods/getSkuDetail')}",
                                data: {skuId: sku_id},
                                type: "get",
                                dataType: "json",
                                success: (res) => {
                                    console.log(res);
                                    $("#sku_stock").val(res.sku_stock);
                                    $("#sku_price").val(res.sku_price);
                                }
                            })
                        }

                    }
                });
            }
        }

        $('.image').on('click', function () {
            var othis = $(this), method = othis.data('method'), url = othis.data('url');
            active[method] ? active[method].call(this, othis, url) : '';
        });

    })

</script>